﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class GuanLi_MailSetting : System.Web.UI.PageEx
{
    private string strPageCode = "S0000G";
    private string strLoginResult = string.Empty;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!DalEx.DbManagerEx.CheckLoginRight(UserType, UserId, strPageCode, ref strLoginResult))
        {
            FineUI.Alert.Show(strLoginResult, FineUI.MessageBoxIcon.Warning);
            Response.Redirect("Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            DataBinds();
            btnReset.OnClientClick = frmObject.GetResetReference();
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int iSelectId = 0;
        int iPort = 0;
        int.TryParse(hfId.Text, out iSelectId);
        string strEmailUser = SqlHelper.String(txtEmailUser.Text);
        string strEmailPwd = SqlHelper.String(txtEmailPwd.Text);
        string strSMTP = SqlHelper.String(txtSMTP.Text);
        string strPort = SqlHelper.String(txtPort.Text);
        string strSendEmail = SqlHelper.String(txtSendEmail.Text);
        string strSendName = SqlHelper.String(txtSendName.Text);
        string strRegisterMail = string.Empty;
        string strOrderMail = string.Empty;
        int.TryParse(strPort, out iPort);
        Model.DbEmail dbEmail = new Model.DbEmail();
        dbEmail.EId = iSelectId;
        dbEmail.EMail = strEmailUser;
        dbEmail.EPwd = strEmailPwd;
        dbEmail.ESmtp = strSMTP;
        dbEmail.EPort = iPort;
        dbEmail.EShowEmail = strSendEmail;
        dbEmail.EShowUser = strSendName;
        dbEmail.ERegisterMail = strRegisterMail;
        dbEmail.EOrderMail = strOrderMail;

        int iResult = 0;
        iResult = dbEmail.EId > 0 ? Dal.DbEmailDal.Update(dbEmail) : Dal.DbEmailDal.Insert(dbEmail);
        if (iResult > 0)
        {
            FineUI.Alert.Show("邮件系统信息已保存！", FineUI.MessageBoxIcon.Information);
        }
        else
        {
            FineUI.Alert.Show("邮件系统信息保存失败！", FineUI.MessageBoxIcon.Error);
        }
    }
    private void DataBinds()
    {
        Model.DbEmail dbEmail = Dal.DbEmailDal.Select(1);
        if (dbEmail != null)
        {
            hfId.Text = dbEmail.EId.ToString();
            txtEmailUser.Text = dbEmail.EMail;
            txtEmailPwd.Text = dbEmail.EPwd;
            txtSendEmail.Text = dbEmail.EShowEmail;
            txtSendName.Text = dbEmail.EShowUser;
            txtSMTP.Text = dbEmail.ESmtp;
            txtPort.Text = dbEmail.EPort.ToString();
            //UEditor1.Value = HttpUtility.HtmlDecode(dbEmail.ERegisterMail);
            //UEditor2.Value = HttpUtility.HtmlDecode(dbEmail.EOrderMail);
        }
    }
}
